const app = getApp();
const _requsetCYZ = require('../../../utils/requestData');
const _functionCYZ = require('../../../utils/common');
var WxParse = require('../../../wxParse/wxParse.js');
Page({
    data: {
        this_cms_id:0,
        this_cms_config: null,
        this_cms_wangdian_top: null,
        this_cms_info: null,
        this_data_share_title: '',
        this_data_share_img: ''
    },
    onLoad: function (op) {
        var that = this;
        that.setData({ this_cms_id:op.id});
        that.get_index_data();
    },
    get_index_data: function () {
        var that = this;
        _functionCYZ.CYZ_loading();
        var requestData = {};
        requestData.id = that.data.this_cms_id;
        _requsetCYZ.cyz_requestGet('/WuliuCmsApiIndex/getWangdianInfo', requestData, function (cyz_data) {
            wx.hideToast();
            if (cyz_data.code == 1) {
                that.setData({
                    this_cms_config: cyz_data.info.this_cms_config,
                    this_cms_wangdian_top: cyz_data.info.this_cms_wangdian_top,
                    this_cms_info: cyz_data.info.this_cms_info
                });
                WxParse.wxParse('article', 'html', cyz_data.info.this_cms_info.w_jieshao, that, 5);
                if (cyz_data.info.this_cms_config != null) {
                    that.setData({
                        this_data_share_title: cyz_data.info.this_cms_config.share_title,
                        this_data_share_img: cyz_data.info.this_cms_config.share_img
                    })
                }
            } else if (cyz_data.code == 2) {
                app.getUserDataToken(function (token) {
                    that.get_index_data();
                });
                return false;
            }
        });
    },
    /**
     * 跳转页面
     */
    onAppNavigateTap: function (e) {
        const dataset = e.detail.target ? e.detail.target.dataset : e.currentTarget.dataset;
        const url = dataset.url, appurl = dataset.appurl, atype = dataset.atype || 1, appId = dataset.appid;
        if (atype == 1) {
            wx.navigateTo({
                url: url, fail: () => {
                    wx.switchTab({
                        url: url,
                    });
                }
            });
        } else if (atype == 2) {
            wx.navigateToMiniProgram({ appId: appId, path: appurl });
        }
    },
    onPullDownRefresh: function () {
        var that = this;
        that.get_index_data();
        setTimeout(() => {
            wx.stopPullDownRefresh()
        }, 1000);
    },
    onShareAppMessage: function () {
        var that = this;
        var sharePath = 'pages/wuliucms/dot_details/dot_details?id='+that.data.this_cms_id;
        return {
            title: '公司网点',
            path: sharePath
        }
    },
    /**
	 * 拨打电话
	 */
    onCallTap: function (e) {
        const mobile = e.currentTarget.dataset.mobile;
        wx.makePhoneCall({
            phoneNumber: mobile,
        });
    },
    //地图跳转
    go_map_info_b: function () {
        var that = this;
        wx.openLocation({
            latitude: parseFloat(that.data.this_cms_info.w_lat),
            longitude: parseFloat(that.data.this_cms_info.w_lng),
            scale: 18,
            address: that.data.this_cms_info.w_address
        });
    },
})